package vo

import (
	"github.com/spf13/cast"
	"honghu_be/dal/po"
)

type ArticleVo struct {
	ArticleId string `json:"article_id"`
	Title     string `json:"title"`
	Abstract  string `json:"abstract"`
	Author    string `json:"author"`
	Content   string `json:"content"`
	Date      string `json:"date"`
}

func (a *ArticleVo) ToPo() *po.Article {
	return &po.Article{
		Title:    a.Title,
		Abstract: a.Abstract,
		Author:   a.Title,
		Content:  a.Content,
	}
}

func ToArticleVo(a *po.Article) *ArticleVo {
	return &ArticleVo{
		ArticleId: cast.ToString(a.ID),
		Title:     a.Title,
		Abstract:  a.Abstract,
		Author:    a.Author,
		Content:   a.Content,
		Date:      a.CreatedAt.Format("2006-01-02"),
	}
}

func ToArticleVos(pos []*po.Article) []*ArticleVo {
	vos := make([]*ArticleVo, len(pos))
	for i := range pos {
		vos[i] = ToArticleVo(pos[i])
	}
	return vos
}
